
const router = require('koa-router')()
const dayjs = require('dayjs');
const { addArticle, queryArticle, deltetArticle, getDetail } = require("../controller/context/article/ARTICLE.CONTROLLER");
const { queryMESSAGE } = require('../controller/context/message/MESSAGE.CONTROLLER');
const { queryUVLOG } = require('../controller/webSite/vistorlogs/vistorlogs-controller');
const { eliminateRedun } = require('../utils/util');
router.prefix("/home");


// 查询今天
router.post("/getMonication", async (ctx, next) => {
    try {
       
        const articleList = await queryArticle({ title: null, subjectId: null });
        const messageList = await queryMESSAGE({ userName: null, _id: null, articleId: null });
        const todayUvList = await queryUVLOG({
            maxDate: new Date(`${dayjs().format("YYYY-MM-DD")} 23:59:59`).getTime(),
            minDate: new Date(`${dayjs().format("YYYY-MM-DD")} 00:00:00`).getTime(),
        })
        const uvRes = eliminateRedun(todayUvList, 'ip')
        ctx.body = {
            status: "0000",
            message: "数据获取成功",
            data: {
                niName: "牧夕",
                asign: "不可丢弃勇敢的心，存这样的心必得大赏赐！",
                headImage: "",
                articleCount: articleList.length,
                messageCount: messageList.length,
                pv: uvRes.length
            }
        }
    } catch (error) {
        console.log(error)
        ctx.body = {
            status: "1000",
            message: "服务器故障"
        }
    }
})







module.exports = router